<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='lb'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">

            <div class="layui-form-item">
                <form name="totalForm" id="totalForm" action="${web_domain}/mall/presell/list" method="get">

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='spmc'/></label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="<fmt:message key='qsrspmc'/>" value="<c:if test='${params.name !=null}'>${params.name}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='spbh'/></label>
                        <div class="layui-input-inline">
                            <input type="text" name="goodsNo" placeholder="<fmt:message key='qsrspmc'/>" value="<c:if test='${params.goodsNo !=null}'>${params.goodsNo}</c:if>" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label"><fmt:message key='splm'/></label>
                        <div class="layui-input-inline">

                            <select lay-verify="required" id="topChannel" lay-filter="topChannel" name="goodsChannel.parent.parent.id">
                                <option value="0"><fmt:message key='qxz'/></option>
                                <c:forEach items="${channels }" var="item">
                                    <option value="${item.id}"
                                            <c:if test="${item.id eq params.goodsChannel.parent.parent.id}">selected="selected"</c:if> >${item.name}</option>
                                </c:forEach>
                            </select>

                        </div>

                        <div class="layui-input-inline middleChannel">
                            <select lay-verify="required" id="middleChannel" lay-filter="middleChannel" name="goodsChannel.parent.id">
                                <option value="0"><fmt:message key='qxz'/></option>
                                <c:forEach items="${params.goodsChannel.parent.parent.children }" var="item">
                                    <option value="${item.id}"
                                            <c:if test="${item.id eq params.goodsChannel.parent.id}">selected="selected"</c:if> >${item.name}</option>
                                </c:forEach>
                            </select>
                        </div>

                        <div class="layui-input-inline bottomChannel">
                            <select lay-verify="required" name="goodsChannel.id" id="bottomChannel" lay-filter="bottomChannel">
                                <option value="0"><fmt:message key='qxz'/></option>
                                <c:forEach items="${params.goodsChannel.parent.children }" var="item">
                                    <option value="${item.id}"
                                            <c:if test="${item.id eq params.goodsChannel.id}">selected="selected"</c:if> >${item.name}</option>
                                </c:forEach>
                            </select>
                        </div>

                    </div>


                    <!-- 需要排序的字段 -->
                    <input type="hidden" class="feijin-orderby" name="orderByCreateTime" id="orderByCreateTimeParams" value="${params.orderByCreateTime}"/>
                    <input type="hidden" class="feijin-orderby" name="orderByStore" id="orderByStoreParams" value="${params.orderByStore}"/>
                    <input type="hidden" class="feijin-orderby" name="orderByPrice" id="orderByPriceParams" value="${params.orderByPrice}"/>
                    <input type="hidden" class="feijin-orderby" name="orderBySalesVolume" id="orderBySalesVolumeParams" value="${params.orderBySalesVolume}"/>
                    <!-- 需要排序的字段 -->
                    <input type="hidden" name="status" value="${params.status}"/>

                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-sm layuiadmin-btn-list" id="search"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> <fmt:message key='ss'/></button>
                    </div>
                </form>
            </div>
        </div>

    </div>

    <div class="layui-card">
        <div class="layui-field-box layui-form">

            <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                <ul class="layui-tab-title">
                    <li
                            <c:if test="${params.presellStatus eq 0}">class="layui-this"</c:if> >
                        <a href="${web_domain}/mall/presell/list"
                           <c:if test="${params.presellStatus eq 0}">style="color: rgb(0, 150, 136)"</c:if> ><fmt:message key='qb'/></a>
                    </li>
                    <li <c:if test="${params.presellStatus eq 1}">class="layui-this"</c:if>>
                        <a href="${web_domain}/mall/presell/list?presellStatus=1" <c:if test="${params.presellStatus eq 1}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='dsh'/></a>
                    </li>
                    <li <c:if test="${params.presellStatus eq 2}">class="layui-this"</c:if>>
                        <a href="${web_domain}/mall/presell/list?presellStatus=2" <c:if test="${params.presellStatus eq 2}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='shz'/></a>
                    </li>
                    <li <c:if test="${params.presellStatus eq 3}">class="layui-this"</c:if>>
                        <a href="${web_domain}/mall/presell/list?presellStatus=3" <c:if test="${params.presellStatus eq 3}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='shtg'/></a>
                    </li>
                    <li <c:if test="${params.presellStatus eq 4}">class="layui-this"</c:if>>
                        <a href="${web_domain}/mall/presell/list?presellStatus=4" <c:if test="${params.presellStatus eq 4}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='shbtg'/></a>
                    </li>
                    <li <c:if test="${params.presellStatus eq 5}">class="layui-this"</c:if>>
                        <a href="${web_domain}/mall/presell/list?presellStatus=5" <c:if test="${params.presellStatus eq 5}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='hdjxz'/></a>
                    </li>
                    <li <c:if test="${params.presellStatus eq 6}">class="layui-this"</c:if>>
                        <a href="${web_domain}/mall/presell/list?presellStatus=6" <c:if test="${params.presellStatus eq 6}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='hdjs'/></a>
                    </li>
                    <li <c:if test="${params.presellStatus eq 7}">class="layui-this"</c:if>>
                        <a href="${web_domain}/mall/presell/list?presellStatus=7" <c:if test="${params.presellStatus eq 7}">style="color: rgb(0, 150, 136)"</c:if>><fmt:message key='yxj'/></a>
                    </li>
                </ul>
            </div>

            <table class="layui-table" lay-size="sm">
                <thead>
                <tr>
                    <th width="5%"><input id="checkboxs" type="checkbox" lay-ignore lay-skin="primary"/></th>
                    <th><fmt:message key='spbh'/></th>
                    <th><fmt:message key='spfm'/></th>
                    <th width="30%"><fmt:message key='spmc'/></th>
                    <th id="orderByPrice">
                        <span><fmt:message key='hdjg'/></span>
                        <span class="layui-table-sort layui-inline" lay-sort="${params.orderByPrice}"><i class="layui-edge layui-table-sort-asc" title="<fmt:message key='sx1'/>"></i><i class="layui-edge layui-table-sort-desc" title="<fmt:message key='jx'/>"></i></span>
                    </th>
                    <th id="orderByStore">
                        <span><fmt:message key='kc'/></span>
                        <span class="layui-table-sort layui-inline" lay-sort="${params.orderByStore}"><i class="layui-edge layui-table-sort-asc" title="<fmt:message key='sx1'/>"></i><i class="layui-edge layui-table-sort-desc" title="<fmt:message key='jx'/>"></i></span>
                    </th>
                    <th id="orderBySalesVolume">
                        <span><fmt:message key='xl'/></span>
                        <span class="layui-table-sort layui-inline" lay-sort="${params.orderBySalesVolume}"><i class="layui-edge layui-table-sort-asc" title="<fmt:message key='sx1'/>"></i><i class="layui-edge layui-table-sort-desc" title="<fmt:message key='jx'/>"></i></span>
                    </th>
                    <th><fmt:message key='djzfsj'/></th>
                    <th><fmt:message key='wkzfsj'/></th>
                    <th><fmt:message key='zt'/></th>
                    <th><fmt:message key='cz'/></th>
                </tr>
                </thead>
                <c:forEach items="${page.result}" var="item" varStatus="status">
                    <tr>
                        <td><input type="checkbox" value="${item.id}" class="feijin-check" lay-ignore lay-skin="primary"/></td>
                        <td>${item.goodsNo }</td>
                        <td><img style="width:40px;height:40px;" class="preview" src="${store_domain}/uploads/${item.defaultImage}"/></td>
                        <td>${item.name}</td>
                        <td><fmt:formatNumber value="${item.presellPrice}" type="CURRENCY"/></td>
                        <td>${item.store}</td>
                        <td>${item.presellSalesVolume}</td>
                        <td>${item.presellSubscriptionPayBeginTime} - ${item.presellSubscriptionPayEndTime}</td>
                        <td>${item.presellRetainagePayBeginTime} - ${item.presellRetainagePayEndTime}</td>
                        <td>
                            <c:choose>
                                <c:when test="${item.presellStatus == 1}"><fmt:message key='dsj'/></c:when>
                                <c:when test="${item.presellStatus == 2}"><fmt:message key='shz'/></c:when>
                                <c:when test="${item.presellStatus == 3}"><fmt:message key='shtg'/></c:when>
                                <c:when test="${item.presellStatus == 4}"><fmt:message key='shbtg'/></c:when>
                                <c:when test="${item.presellStatus == 5}"><fmt:message key='hdks'/></c:when>
                                <c:when test="${item.presellStatus == 6}"><fmt:message key='hdjs'/></c:when>
                                <c:when test="${item.presellStatus == 7}"><fmt:message key='xj'/></c:when>
                            </c:choose>
                        </td>
                        <td>
                            <div class="layui-btn-container">
                                <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-xs feijin-detail"><fmt:message key='ck'/></a>
                                <c:choose>
                                    <c:when test="${item.presellStatus eq 2}">
                                        <a href="javascript:void(0);" data-id="${item.id}" class="layui-btn layui-btn-normal layui-btn-xs feijin-process"><fmt:message key='sh'/></a>
                                    </c:when>
                                </c:choose>
                            </div>
                        </td>
                    </tr>
                </c:forEach>
            </table>
            <jsp:include page="/commons/page.jsp" flush="true"/>
        </div>
    </div>

</div>

<script>

    $(function () {

        //全选反选
        $("#checkboxs").click(function () {
            if (this.checked) {
                $(".feijin-check:checkbox").prop("checked", true);
            } else {
                $(".feijin-check:checkbox").prop("checked", false);
            }
        });


        layui.use(['form', 'laydate'], function () {

            var form = layui.form;
            var laydate = layui.laydate;

            //加载二级商品类目
            form.on('select(topChannel)', function (data) {
                if (data.elem != data.value) {
                    var id = $("#topChannel").val();
                    $(".middleChannel").html("");
                    $(".bottomChannel").html("");

                    $.ajax({
                        url: "${web_domain}/mall/goods/childChannels?id=" + id,
                        type: "get",
                        dataType: "JSON",
                        success: function (result) {
                            if (result.status && result.result != null) {
                                var channelsHTML = "<select lay-verify='required' id='middleChannel' class='layui-input' lay-filter='middleChannel' name='goodsChannel.parent.id'>" +
                                    "<option value='0'><fmt:message key='qxz'/></option>";
                                $.each(result.result, function (index, item) {
                                    channelsHTML += "<option value='" + item.id + "' >" + item.name + "</option>"
                                });
                                channelsHTML += "</select>";

                                $(".middleChannel").html(channelsHTML);
                                form.render('select');//重新渲染
                            }
                        }
                    });
                }
            });

            //加载三级商品类目
            form.on('select(middleChannel)', function (data) {
                if (data.elem != data.value) {
                    var id = $("#middleChannel").val();
                    $(".bottomChannel").html("");

                    $.ajax({
                        url: "${web_domain}/mall/goods/childChannels?id=" + id,
                        type: "get",
                        dataType: "JSON",
                        success: function (result) {
                            if (result.status && result.result != null) {
                                var channelsHTML = "<select lay-verify='required' name='goodsChannel.id' id='bottomChannel' class='layui-input' lay-filter='bottomChannel'>" +
                                    "<option value='0'><fmt:message key='qxz'/></option>";
                                $.each(result.result, function (index, item) {
                                    channelsHTML += "<option value='" + item.id + "' >" + item.name + "</option>"
                                });
                                channelsHTML += "</select>";
                                $(".bottomChannel").html(channelsHTML);
                                form.render('select');//重新渲染
                            }
                        }
                    });
                }
            });
        });


        //审核
        $(".feijin-process").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='shys'/>'
                , content: '${web_domain}/mall/presell/' + id + '/process'
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='bc'/>', '<fmt:message key='qx'/>']
                , yes: function (index, layero) {
                    var submit = layero.find('iframe').contents().find("#submit");
                    submit.click();
                }
            });
        });

        //查看详情
        $(".feijin-detail").click(function () {

            var id = $(this).attr("data-id");

            layer.open({
                type: 2
                , title: '<fmt:message key='ckxq'/>'
                , content: '${web_domain}/mall/presell/' + id + '/detail'
                , maxmin: true
                , area: ['97%', '97%']
                , btn: ['<fmt:message key='fh'/>']
            });
        });


        //按时间排序
        $("#orderByCreateTime").click(function () {
            $(".feijin-orderby").attr("value", "");
            var orderBy = "${params.orderByCreateTime}";

            if (orderBy == "asc") {
                $("#orderByCreateTimeParams").attr("value", "");
                $("#search").click();
                return;
            }

            if (orderBy == "desc") {
                $("#orderByCreateTimeParams").attr("value", "asc");
                $("#search").click();
                return;
            }

            if (orderBy == "") {
                $("#orderByCreateTimeParams").attr("value", "desc");
                $("#search").click();
                return;
            }
        });

        //按价格排序
        $("#orderByPrice").click(function () {
            $(".feijin-orderby").attr("value", "");
            var orderBy = "${params.orderByPrice}";

            if (orderBy == "asc") {
                $("#orderByPriceParams").attr("value", "");
                $("#search").click();
                return;
            }

            if (orderBy == "desc") {
                $("#orderByPriceParams").attr("value", "asc");
                $("#search").click();
                return;
            }

            if (orderBy == "") {
                $("#orderByPriceParams").attr("value", "desc");
                $("#search").click();
                return;
            }
        });

        //按库存排序
        $("#orderByStore").click(function () {
            $(".feijin-orderby").attr("value", "");
            var orderBy = "${params.orderByStore}";

            if (orderBy == "asc") {
                $("#orderByStoreParams").attr("value", "");
                $("#search").click();
                return;
            }

            if (orderBy == "desc") {
                $("#orderByStoreParams").attr("value", "asc");
                $("#search").click();
                return;
            }

            if (orderBy == "") {
                $("#orderByStoreParams").attr("value", "desc");
                $("#search").click();
                return;
            }
        });

        //按销量排序
        $("#orderBySalesVolume").click(function () {
            $(".feijin-orderby").attr("value", "");
            var orderBy = "${params.orderBySalesVolume}";

            if (orderBy == "asc") {
                $("#orderBySalesVolumeParams").attr("value", "");
                $("#search").click();
                return;
            }

            if (orderBy == "desc") {
                $("#orderBySalesVolumeParams").attr("value", "asc");
                $("#search").click();
                return;
            }

            if (orderBy == "") {
                $("#orderBySalesVolumeParams").attr("value", "desc");
                $("#search").click();
                return;
            }
        });


    });
</script>
</body>
</fmt:bundle>
</html>
